import akka.actor.{ Actor, ActorSystem, Props }
import scala.io.StdIn

class PersonActor extends Actor {
    import context._

    def angry: Receive = {
        case "foo" => println("I'm angry")
        case "bar" => become(happy)
    }

    def happy: Receive = {
        case "foo" => become(angry)
        case "bar" => println("I'm Happy")
    }

    def receive = {
        case "foo" => become(angry)
        case "bar" => become(happy)
    }
}

object PersonActor {
    def props = Props[PersonActor]
}

object Become extends App {
    val system = ActorSystem("Person")
    try{
    
        val hitman = system.actorOf(PersonActor.props, "hitman")

        hitman ! "foo"
        hitman ! "foo"
        hitman ! "bar"

        StdIn.readLine()
    } finally {
        system.terminate()
    }

}